package com.wxq.workpad.accoutInfo


import com.tencent.mmkv.MMKV
import com.wxq.workpad.entity.LoginResult
import com.wxq.workpad.entity.UserInfoDTO
import com.wxq.workpad.entity.parmer.LoginParmer


/**
 * 用户相关的所有信息
 */
object UserInfoManager {


    const val AUTOLOGIN = "autologin"

    const val ACCOUNT = "account"
    const val PASSWORD = "password"
    const val LAST_SMS_UPLOAD_TIME = "last_sms_upload_time"
    const val LAST_PHONE_UPLOAD_TIME = "last_phone_upload_time"
    const val CUSTOMERLIST = "customerlist"

    const val TOKEN = "token"

    var ticket:String = ""
    var sign:String = ""
    var ts:String = ""
    lateinit var  userInfoDTO: UserInfoDTO
    //所有的登录后的信息
    lateinit var  mLoginResult: LoginResult

    var Authorization:String ?
    get() {
        return  MMKV.defaultMMKV().getString(TOKEN,"")
    }
    set(value) {
        MMKV.defaultMMKV().putString(TOKEN, value);
    }




    init {

    }

    fun isAutoLogin():Boolean{
      return  MMKV.defaultMMKV().getBoolean(AUTOLOGIN, false);
    }

    fun setAuToLogin(autoLogin:Boolean){
        if (!autoLogin){
            Authorization=""
            MMKV.defaultMMKV().putString(PASSWORD,"")
            MMKV.defaultMMKV().putString(ACCOUNT,"")
        }
          MMKV.defaultMMKV().putBoolean(AUTOLOGIN,autoLogin)
    }

    fun saveLoginInfo(    username:String,password:String){
          MMKV.defaultMMKV().putString(PASSWORD,password)
          MMKV.defaultMMKV().putString(ACCOUNT,username)
    }


      fun saveLoginInfo(parmer: LoginParmer,  loginResult: LoginResult){
          MMKV.defaultMMKV().putString(PASSWORD,parmer.password)
          MMKV.defaultMMKV().putString(ACCOUNT,parmer.userName)
          ticket=loginResult.ticket
          sign=loginResult.sign
          ts=loginResult.ts
          mLoginResult=loginResult
    }






    fun getAccount():String?{
      return  MMKV.defaultMMKV().getString(ACCOUNT,"")
    }

     fun getPwd():String?{
      return  MMKV.defaultMMKV().getString(PASSWORD,"")
    }


    // 当前用户下的所有 手机号 默认为空

    fun saveSmsUploadTime(time:String?){
        time?.let {
            MMKV.defaultMMKV().putString(LAST_SMS_UPLOAD_TIME,it)
        }
    }
    fun getSmsUploadTime():String?{
        return MMKV.defaultMMKV().getString(LAST_SMS_UPLOAD_TIME,null)
    }


     fun savePhoneCallUploadTime(time:String?){
        time?.let {
            MMKV.defaultMMKV().putString(LAST_PHONE_UPLOAD_TIME,it)
        }
    }
    fun getPhoneCallUploadTime():String?{
        return MMKV.defaultMMKV().getString(LAST_PHONE_UPLOAD_TIME,null)
    }




}